<?php

namespace s\controllers;

use Yii;
use yii\web\Controller;
use yii\web\UploadedFile;

class SiteController extends Controller
{

    public function actionIndex()
    {
        exit;
    }

    public function actionUpload()
    {
        $file = UploadedFile::getInstanceByName('file');
        if (!$file) {
            return $this->err('请选择要上传的文件');
        }
        if ($file->error != 0) {
            return $this->err('上传资源不正确');
        }
        var_dump($file);
        exit;
        $fileName = md5(rand(1, 9999).time()).'.'.$fileExt;
        $date = date('Ymd');
        $y = substr($date, 0, 4);
        $m = substr($date, 4, 2);
        $d = substr($date, 6, 2);
        $filePath =  $fileConfig['path'].'/'.$y.$m.'/'.$d.'/';
        $saveDir = $config['tmp_path'] . $filePath;
        is_dir($saveDir) or mkdir($saveDir, 0777, true);
        $save = $file->saveAs($saveDir.$fileName);
        if ($save) {
            return $this->ok('上传成功', [
                'filename' => $file->name,
                'filepath' => $saveDir . $fileName,
            ]);
        }
        return $this->err('上传失败，请重试');
    }



}
